---
sidebar_position: 3.01
description: Learn how to generate a mouse click with an air pressure sensor
  using TypeScript and the HidMouse class from the ds library. Tune the pressure
  threshold to detect a user blowing on the sensor and optimize debouncing with
  observables.
keywords:
  - air pressure sensor
  - mouse click
  - TypeScript
  - HidMouse
  - ds library
---
# Commands

Let's assume that `1400` hPa is a threshold high enough
to detect a user blowing on the sensor; then we
can add code to generate a mouse click.

`1400` is rater arbitrary and this is the kind of constants
that you will want to tune using the actual hardware sensors,
not just a simulator.

```ts skip no-run
if (pressure > 1400) {
    await mouse.setButton(ds.HidMouseButton.Left, ds.HidMouseButtonEvent.Click)
}
```

The full sample looks like this.

```ts edit
console.log("starting...")
const sensor = new ds.AirPressure()
const mouse = new ds.HidMouse()
// listen for pressure changes
sensor.reading.subscribe(async pressure => {
    console.log(pressure)
    // user blows in straw
    if (pressure > 1400) {
        // click!
        console.log(`click!`)
        await mouse.setButton(
            ds.HidMouseButton.Left,
            ds.HidMouseButtonEvent.Click
        )
        // debouncing
        await ds.sleep(50)
    }
})
```

To get better debouncing, see [observables](/developer/observables).
